// pages/resource-view/statistics/village-details/index.js
const app = getApp();
const { AskPage } = app._require("common/index");
// import { staticUrl } from "./services/config.js";
var WxParse = require("../../../../wxParse/wxParse");
import { staticUrl } from "../../../../services/config";
AskPage({
  /**
   * 页面的初始数据
   */
  data: {
    contentInfo: {},
    banner: [],
    id: "",
    richText: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDetails(options.id);
    this.setData({
      id: options.id,
    });
  },
  loadRichHtml(htmlValue) {
    var htmlTpl = htmlValue;
    WxParse.wxParse("richText", "html", htmlTpl, this, 5);
  },
  // 获取详情数据
  async getDetails(id) {
    const res = await this.$_server("details/data", {
      params: {
        id: id,
      },
    });
    if (res.data.code === 200) {
      const list = res.data.data.advertisingMap
        ? res.data.data.advertisingMap.split(",").map((item) => {
            return {
              path: staticUrl + "/" + item,
            };
          })
        : [];
      this.setData({
        contentInfo: res.data.data,
        banner: list,
        richText: res.data.data.introduction,
      });
      if (this.data.richText) {
        this.loadRichHtml(this.data.richText);
      }
      wx.setNavigationBarTitle({
        title: res.data.data.shortName + "资源情况", //页面切换，更换页面标题
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getDetails(this.data.id);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
